import fetch from "@/utils/fetch";

const rolelist = {
  state: {
    rolelist: [],
    sbulist: []
  },
  mutations: {
    GET_ROLELIST: (state, rolelist) => {
      state.rolelist = rolelist;
    },
    GET_SBULIST: (state, sbulist) => {
      state.sbulist = sbulist;
    }
  },
  actions: {
    getrolelist({ commit }) {
      return new Promise((resolve, reject) => {
        fetch
          .rolelist()
          .then(response => {
            const rolelist = response.userrole;
            const sbulist = response.sbuid;
            commit("GET_ROLELIST", rolelist);
            commit("GET_SBULIST", sbulist);
            resolve(response);
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  }
};

export default rolelist;
